
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmMenu.java
 *
 * Created on 6/Mai/2011, 15:03:45
 */

/**
 *
 * @author Bruno
 */
public class FrmMenu extends javax.swing.JFrame {

    /** Creates new form FrmMenu */
    public FrmMenu() {
        initComponents();
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation(screenSize.width/2 - getWidth()/2, screenSize.height/2 - getHeight()/2);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grpWhite = new javax.swing.ButtonGroup();
        grpBlack = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        cmdPlay = new javax.swing.JButton();
        cmdExit = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        sldSize = new javax.swing.JSlider();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        optWhiteHuman = new javax.swing.JRadioButton();
        optWhiteEasy = new javax.swing.JRadioButton();
        optWhiteMedium = new javax.swing.JRadioButton();
        optWhiteHard = new javax.swing.JRadioButton();
        jPanel6 = new javax.swing.JPanel();
        optBlackHuman = new javax.swing.JRadioButton();
        optBlackEasy = new javax.swing.JRadioButton();
        optBlackMedium = new javax.swing.JRadioButton();
        optBlackHard = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("HEX");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("HEX");
        getContentPane().add(jLabel1, java.awt.BorderLayout.NORTH);

        cmdPlay.setText("Jogar");
        cmdPlay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdPlayActionPerformed(evt);
            }
        });
        jPanel1.add(cmdPlay);

        cmdExit.setText("Sair");
        cmdExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdExitActionPerformed(evt);
            }
        });
        jPanel1.add(cmdExit);

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        jPanel2.setLayout(new java.awt.BorderLayout());

        jLabel2.setText("Tamanho do tabuleiro (entre " + Board.MIN_SIZE + " e " + Board.MAX_SIZE + "):");
        jPanel3.add(jLabel2);

        sldSize.setMajorTickSpacing(3);
        sldSize.setMaximum(Board.MAX_SIZE);
        sldSize.setMinimum(Board.MIN_SIZE);
        sldSize.setMinorTickSpacing(1);
        sldSize.setPaintLabels(true);
        sldSize.setPaintTicks(true);
        sldSize.setSnapToTicks(true);
        sldSize.setValue(Board.DEFAULT_SIZE);
        jPanel3.add(sldSize);

        jPanel2.add(jPanel3, java.awt.BorderLayout.NORTH);

        jPanel4.setLayout(new java.awt.GridLayout(1, 2));

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Jogador branco"));
        jPanel5.setLayout(new javax.swing.BoxLayout(jPanel5, javax.swing.BoxLayout.PAGE_AXIS));

        grpWhite.add(optWhiteHuman);
        optWhiteHuman.setSelected(true);
        optWhiteHuman.setText("Humano");
        jPanel5.add(optWhiteHuman);

        grpWhite.add(optWhiteEasy);
        optWhiteEasy.setText("Computador fácil");
        jPanel5.add(optWhiteEasy);

        grpWhite.add(optWhiteMedium);
        optWhiteMedium.setText("Computador médio");
        jPanel5.add(optWhiteMedium);

        grpWhite.add(optWhiteHard);
        optWhiteHard.setText("Computador difícil");
        jPanel5.add(optWhiteHard);

        jPanel4.add(jPanel5);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Jogador preto"));
        jPanel6.setLayout(new javax.swing.BoxLayout(jPanel6, javax.swing.BoxLayout.PAGE_AXIS));

        grpBlack.add(optBlackHuman);
        optBlackHuman.setSelected(true);
        optBlackHuman.setText("Humano");
        jPanel6.add(optBlackHuman);

        grpBlack.add(optBlackEasy);
        optBlackEasy.setText("Computador fácil");
        jPanel6.add(optBlackEasy);

        grpBlack.add(optBlackMedium);
        optBlackMedium.setText("Computador médio");
        jPanel6.add(optBlackMedium);

        grpBlack.add(optBlackHard);
        optBlackHard.setText("Computador difícil");
        jPanel6.add(optBlackHard);

        jPanel4.add(jPanel6);

        jPanel2.add(jPanel4, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExitActionPerformed
		System.exit(0);
	}//GEN-LAST:event_cmdExitActionPerformed

	private void cmdPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdPlayActionPerformed
		// Iniciar o jogo
		Hex.board = new Board(sldSize.getValue());

		if(optWhiteHuman.isSelected())
			Hex.whitePlayer = Player.HUMAN;
		else if(optWhiteEasy.isSelected())
			Hex.whitePlayer = Player.CPU_EASY;
		else if(optWhiteMedium.isSelected())
			Hex.whitePlayer = Player.CPU_MEDIUM;
		else
			Hex.whitePlayer = Player.CPU_HARD;

		if(optBlackHuman.isSelected())
			Hex.blackPlayer = Player.HUMAN;
		else if(optBlackEasy.isSelected())
			Hex.blackPlayer = Player.CPU_EASY;
		else if(optBlackMedium.isSelected())
			Hex.blackPlayer = Player.CPU_MEDIUM;
		else
			Hex.blackPlayer = Player.CPU_HARD;

		// Escolher o jogador que inicia o jogo
		int player = (int)(Math.random() * 2.0);
		if(player == 0) {
			Hex.currentPlayer = Color.WHITE;
			JOptionPane.showMessageDialog(null, "O primeiro a jogar é o jogador branco!", "HEX", JOptionPane.PLAIN_MESSAGE);
		}
		else {
			Hex.currentPlayer = Color.BLACK;
			JOptionPane.showMessageDialog(null, "O primeiro a jogar é o jogador preto!", "HEX", JOptionPane.PLAIN_MESSAGE);
		}

		Hex.hexGraphical.frmGame = new FrmGame();
		Hex.hexGraphical.frmGame.setVisible(true);
		setVisible(false);
	}//GEN-LAST:event_cmdPlayActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdExit;
    private javax.swing.JButton cmdPlay;
    private javax.swing.ButtonGroup grpBlack;
    private javax.swing.ButtonGroup grpWhite;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JRadioButton optBlackEasy;
    private javax.swing.JRadioButton optBlackHard;
    private javax.swing.JRadioButton optBlackHuman;
    private javax.swing.JRadioButton optBlackMedium;
    private javax.swing.JRadioButton optWhiteEasy;
    private javax.swing.JRadioButton optWhiteHard;
    private javax.swing.JRadioButton optWhiteHuman;
    private javax.swing.JRadioButton optWhiteMedium;
    private javax.swing.JSlider sldSize;
    // End of variables declaration//GEN-END:variables

}
